
package ija.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import ija.controller.MainController;

public class MainMenuContent extends JPanel {
    
	private static final long serialVersionUID = -5966873039537476653L;
	private MainController mcParent;
	private JButton bNewGame, bReplayer, bAbout, bExitGame;
	private JLabel lCaption;
	
	public MainMenuContent(MainController mcParent){
		super(new BorderLayout());
    	this.mcParent = mcParent;
		setPreferredSize(new Dimension(720,720));
		addWidgets();
	};
	
    private void addWidgets() {
    	lCaption = new JLabel("CHECKERS", SwingConstants.CENTER);
        lCaption.setPreferredSize(new Dimension(300, 100));
        
        bNewGame = new JButton("Start game");
        bNewGame.setPreferredSize(new Dimension(200, 20));
        bNewGame.addActionListener(new NewGame());
        
        bReplayer = new JButton("Game Replayer");
        bReplayer.setPreferredSize(new Dimension(200, 20));
        bReplayer.addActionListener(new Replayer());
        
        bAbout = new JButton("About");
        bAbout.setPreferredSize(new Dimension(200, 20));
        bAbout.addActionListener(new About());
        
        bExitGame = new JButton("Exit game");
        bExitGame.setPreferredSize(new Dimension(200, 50));     
        bExitGame.addActionListener(new ExitGame()); 
        
        GroupLayout layout = new GroupLayout(this);
        setLayout(layout);
		layout.setAutoCreateGaps(true);
		layout.setAutoCreateContainerGaps(true);
        layout.setHorizontalGroup(
	       layout.createSequentialGroup() 
	           .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	           .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING,true) 
	               .addComponent(lCaption,GroupLayout.Alignment.CENTER)
	               .addComponent(bNewGame,GroupLayout.Alignment.CENTER)
	               .addComponent(bReplayer,GroupLayout.Alignment.CENTER)
	               .addComponent(bAbout,GroupLayout.Alignment.CENTER)
	               .addComponent(bExitGame,GroupLayout.Alignment.CENTER)
	           )    
	           .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	    );
				
		layout.setVerticalGroup(
			layout.createSequentialGroup()
			   .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
			   .addComponent(lCaption)
			   .addComponent(bNewGame)
	           .addComponent(bReplayer)
	           .addComponent(bAbout)
	           .addComponent(bExitGame)
	           .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
		);
    }
    public class NewGame implements ActionListener {
        public void actionPerformed(ActionEvent event) {
        	mcParent.showGameMenu();
        }
    }
    
    public class Replayer implements ActionListener {
        public void actionPerformed(ActionEvent event) {
        	mcParent.showReplayerMenu();
        }
    }
    
    public class About implements ActionListener {
        public void actionPerformed(ActionEvent event) {
           	System.out.println("About");
        }
    }
    
    public class ExitGame implements ActionListener {
        public void actionPerformed(ActionEvent event) {
           	System.exit(0);
        }
    }    
}
